package com.springai.config;

import com.springai.constants.SystemConstants;
import com.springai.tools.CourseTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.springai.constants.SystemConstants.CUSTOMER_SERVICE_SYSTEM;

@Configuration
public class CommonConfiguration {
    //注意参数中的model 就是使⽤的模型，这⾥⽤了Ollama，也可以选择OpenAIChatModel
    @Bean
    public ChatClient chatClient(OllamaChatModel model) {
        return ChatClient.builder(model) //创建ChatClient⼯⼚
                .defaultSystem("你是一个机器人模型，名字叫Aurora，用来帮助别人回答问题")
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultAdvisors(new MessageChatMemoryAdvisor(chatMemory()))
                .build(); //构建ChatClient实例

    }

    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }

    @Bean
    public ChatClient gameChatClient(OpenAiChatModel model, ChatMemory
            chatMemory) {
        return ChatClient
                .builder(model)
                .defaultSystem(SystemConstants.GAME_SYSTEM_PROMPT)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory)
                )
                .build();
    }



        @Bean
        public ChatClient serviceChatClient(
                OpenAiChatModel model,
                ChatMemory chatMemory,
                CourseTools courseTools) {
            return ChatClient.builder(model)
                    .defaultSystem(CUSTOMER_SERVICE_SYSTEM)
                    .defaultAdvisors(
                            new MessageChatMemoryAdvisor(chatMemory), // CHATMEMORY
            new SimpleLoggerAdvisor())
                    .defaultTools(courseTools)
                    .build();
        }


}
